<?php
/**
 * Klasse zum erstellen eines Navbar
 *
 * @author		Joachim Ruf, Loresoft Software (http://www.loresoft.de)
 * @license		New BSD License
 * @version		Class for Bootstrap v2.3.2
 *
 * */


Class Bootstrap_Navbar_Handler
{
	private $arrEntry			= array();
	private $class				= NULL;

	private $arrListing			= array();
	private $brandLeft			= NULL;
	private $brandRight			= NULL;

	private $contentContainer	= '';
	private $arrContainer		= array();
	private $arrBrand			= array();

	private $contentNavbarTop		= '';
	private $contentNavbarBottom	= '';
	private $arrNavbar				= array();

	private $autoActive			= false;
	private $backwardReversing	= false;


	/**
	 * @param string $_title	: Beschriftung
	 * */
	function __construct () {
	}


	public function setNavbar ($_arrNavbar = array()) {
		$this->arrNavbar			= $_arrNavbar;
	}
	public function setNavbarTop ($_contentTop) {
		$this->contentNavbarTop		= $_contentTop;
	}
	public function setNavbarBottom ($_contentBottom) {
		$this->contentNavbarBottom	= $_contentBottom;
	}


	public function setContainer ($_content, $_arrContainer = array()) {
		$this->contentContainer	= $_content;
		$this->arrContainer		= $_arrContainer;
	}


	public function setBrand ($_arrBrand = array()) {
		$this->arrBrand		= $_arrBrand;
	}


	/**
	 * Content links vom Menue
	 * @param string $_content	: Auszugebender Content
	 * @return Void
	 * */
	public function setBrandLeft ($_content) {
		$this->brandLeft	= $_content;
	}


	/**
	 * Content rechts vom Menue
	 * @param string $_content	: Auszugebender Content
	 * @return Void
	 * */
	public function setBrandRight ($_content) {
		$this->brandRight	= $_content;
	}


	public function setListing ($_arrListing = array()) {
		$this->arrListing		= $_arrListing;
	}


	private function getParameter ($_class, array $_arrListing) {
		$result	= NULL;

		if (isset($_arrListing['class'])) { // Class-Parameter verbinden
			$_arrListing['class']	= $_arrListing['class'].' '.$_class;
		} else {
			$_arrListing['class']	= $_class;
		}

		foreach ($_arrListing as $key => $val) {
			$result	.= ' '.$key.'="'.$val.'"';
		}

		return $result;
	}


	/**
	 * Liefert eine Zeile zurueck.
	 * @param string $_content	: Auszugebender Content
	 * @param array	$_arrListing	: array('href' => 'url', 'title' => 'Title-Text', 'rel' => 'follow|nofollow|..')
	 * @return Bootstrap_Navbar_Entry
	 * */
	public function setTitle ($_content, array $_arrListing = array()) {
		return $title = new Bootstrap_Navbar_Entry($_content, $_arrListing);
	}


	/**
	 * Versucht anhand der Url, den aktuellen Eintrag automatisch zu setzen
	 * */
	public function setAutoActive ($_enableBackwardReversing = false) {
		$this->backwardReversing	= $_enableBackwardReversing;
		$this->autoActive	= true;
	}


	/**
	 * Liefert eine Zeile zurueck.
	 * @param string $_content	: Auszugebender Content
	 * @param array	$_arrListing	: array('href' => 'url', 'title' => 'Title-Text', 'rel' => 'follow|nofollow|..')
	 * @return Bootstrap_Navbar_Entry
	 * */
	public function addEntry ($_content, array $_arrListing = array(), $_useTag = 'a') {
		return $this->arrEntry[] = new Bootstrap_Navbar_Entry($_content, $_arrListing, $_useTag);
	}


	/**
	 * Liefert eine Zeile zurueck.
	 * @param int $i	: Auszugebende Zeile
	 * @return Bootstrap_Navbar_Entry
	 * */
	public function get ($i) {
		if (!isset($this->arrEntry[$i])) {
			return NULL;
		}

		return $this->arrEntry[$i];
	}


	/**
	 * @desc Liefert alle Zeilen zurueck.
	 * @return Yapary_Form_Formular_Row[]
	 * */
	public function getList () {
		return $this->arrEntry;
	}


	/**
	 * Loescht einen Eintrag.
	 * @param string $id	: Zu loeschender Eintrag
	 * @return bool
	 * */
	public function delete ($i) {
		if (!isset($this->arrEntry[$i])) {
			return false;
		}

		unset($this->arrEntry[$i]);
		return true;
	}


	/**
	 * @desc Gibt das Grid aus.
	 * @return string
	 * */
	public function display() {
		$result	= NULL;
		$class	= NULL;
		if ($this->class !== NULL) {
			$class	= ' class="'.$this->class.'"';
		}

		if (count($this->arrEntry)) {
			/* @var $oRow Bootstrap_Navbar_Entry */
			foreach ($this->arrEntry as $key => $oRow) {
				$result .=	$oRow->display($this->autoActive, $this->backwardReversing);
			}
		}

		return '<div'.$this->getParameter('navbar', $this->arrNavbar).'>
					'.$this->contentNavbarTop.'
					<div'.$this->getParameter('navbar-inner', $this->arrBrand).'>
						'.$this->brandLeft.'
						<div'.$this->getParameter('container', $this->arrContainer).'>
							'.$this->contentContainer.'
							<ul'.$this->getParameter('nav', $this->arrListing).'>
								'.$result.'
							</ul>
							'.$this->brandRight.'
			            </div>
						'.$this->contentNavbarBottom.'
					</div>
				</div>';

	}


}


?>